package com.skycong.hello77.util;

import java.util.regex.Pattern;

/**
 * Created by wangqi on 18/1/11.
 */

public class Validator {


    private static final String EMAIL = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
    private static final String PHONE = "^[1][0-9]{10}$";


    /**
     * 校验邮箱
     *
     * @param email
     * @return true if the str is email else false
     */
    public static boolean isEmail(String email) {
        return Pattern.matches(EMAIL, email);
    }

    /**
     * 校验手机号
     *
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        return Pattern.matches(PHONE, phone);
    }

    /**
     * 校验密码的长度【6 - 16】
     *
     * @param password
     * @return true if password length in [6-16]  else false
     */
    public static boolean isPassword(String password) {
        if (password == null || "".equals(password))
            return false;
        int length = password.length();
        if (length < 6 || length > 16)
            return false;
        return true;
    }
}
